(define (average x y)
    (/ (+ x y) 2))

(define (square x) (* x x))

(define (good-enough? guess x)
    (< (abs (- (square guess) x)) 0.001))

(define (improve guess x)
    (average guess (/ x guess)))

(define (new-if predicate then-clause else-clause)
    (cond (predicate then-clause)
        (else else-clause)))
        
(newline)
(display "sqrt(): ")
(define (sqrt-iter guess x)
    (new-if (good-enough? guess x)
        guess
        (sqrt-iter (improve guess x)
            x)))

(define (sqrt x)
    (sqrt-iter 1.0 x))
(display (sqrt 2))
(newline)
;TODO
;会陷入死循环。
;这正是正则序与应用序的区别：全部展开再归约和短路归约。
;因为 if 是一个特殊形式，所以它会采用短路归约，而非全部展开